package com.yun.algorithmproblem.leetcode;

import com.yun.datastructure.tree.binarytree.domain.TreeNode;

import java.util.*;

public class Leetcode107 {
    public List<List<Integer>> levelOrderBottom(TreeNode root) {
        List<List<Integer>> levelOrder=new ArrayList<>();
        if(root==null){
            return levelOrder;
        }
        Queue<TreeNode> queue=new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()){
            List<Integer> level=new ArrayList<>();
            int size=queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode curr=queue.poll();
                level.add(curr.val);
                if(curr.left!=null){
                    queue.offer(curr.left);
                }
                if(curr.right!=null){
                    queue.offer(curr.right);
                }
            }
            levelOrder.add(0,level);
        }
        return levelOrder;
    }

    public static void main(String[] args) {

    }
}
